#include "imageeditwidget.h"
#include "ui_imageeditwidget.h"

ImageEditWidget::ImageEditWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::ImageEditWidget)
{
    ui->setupUi(this);
    connect(ui->okBtn,&QPushButton::clicked,[=](){
        Save();
    });
}

ImageEditWidget::~ImageEditWidget()
{
    delete ui;
}

void ImageEditWidget::ShowRenderTarget(RenderTarget *rt)
{
    curImage = rt;
    if(!rt)
    {
        //恢复
        ui->okBtn->setDisabled(true);
        ui->x->setValue(0);
        ui->y->setValue(0);
        ui->size->setValue(1);
        return;
    }
    ui->okBtn->setDisabled(false);
    ui->x ->setValue(rt->GetPos().x());
    ui->y->setValue(rt->GetPos().y());
    ui->size->setValue(rt->sizeTimes);
}

void ImageEditWidget::Save()
{
    if(!curImage)
        return;
    curImage->SetPos(QVector2D(ui->x->value(),ui->y->value()));
    curImage->sizeTimes = ui->size->value();
}
